Skip to content

Fixed nodeToString() to return valid HTML - #110

Merged
codelucas merged 1 commit into
codelucas:masterfrom
0x0ece:patch-2
Feb 6, 2015
Merged

Fixed nodeToString() to return valid HTML#110
codelucas merged 1 commit into
codelucas:masterfrom
0x0ece:patch-2

Conversation

@0x0ece

@0x0ece 0x0ece commented Jan 15, 2015

Copy link
Copy Markdown
Contributor

In some cases the output of nodeToString() is not valid HTML, e.g. for iframe nodes.

Solution found here: http://stackoverflow.com/questions/27020950/lxml-modify-tags-prevent

An example of bad behavior is an article with a youtube video inside. The video embed code is transformed into <iframe ... />, that is not valid, and thus the result in the browser is a page with no visible content after the video.

In some cases the output of nodeToString() is not valid HTML, e.g. for iframe nodes.

Solution found here: http://stackoverflow.com/questions/27020950/lxml-modify-tags-prevent

An example of bad behavior is an article with a youtube video inside. The video embed code is transformed into `<iframe ... />`, that is not valid, and thus the result in the browser is a page with no visible content after the video.
@0x0ece 0x0ece changed the title Fix nodeToString() to return valid HTML Fixed nodeToString() to return valid HTML Jan 15, 2015
@codelucas

Copy link
Copy Markdown
Owner

Testing this locally right now, thanks for another good PR @ecesena!

@codelucas

Copy link
Copy Markdown
Owner

@ecesena Your work is good, it's gonna be a little longer until I merge, currently trying to fix some things on the python-2 branch.

@0x0ece

0x0ece commented Jan 18, 2015

Copy link
Copy Markdown
Contributor Author

Thank you, no rush on my side - I'll pull req something more complex for the title extraction by the end of the day.

@codelucas
codelucas merged commit 5cdc5d0 into codelucas:master Feb 6, 2015
@codelucas

Copy link
Copy Markdown
Owner

Good job, I'll port these changes to the python-2 branch today as well.

I was a bit concerned at first because I thought changing the HTML output that much in Parser.nodeToString would mess with the fulltext algorithm but apparently over 140 tests it didn't.

nodeToString is mostly used to get HTML output anyways (article HTML and video embed code).
I don't think we'd ever see a use case where method isn't equal to 'html', so good find!

@0x0ece

0x0ece commented Feb 6, 2015

Copy link
Copy Markdown
Contributor Author

Great to know that it didn’t take too much effort! I was likewise surprised to discover that <iframe/> is not valid html.

On Feb 6, 2015, at 4:18 AM, Lucas Ou-Yang notifications@github.com wrote:

Good job, I'll port these changes to the python-2 branch today as well.

I was a bit concerned at first because I thought changing the HTML output that much in Parser.nodeToString would mess with the fulltext algorithm but apparently out 140 tests it didn't.

nodeToString is mostly used to get HTML output anyways (article HTML and video embed code).
I don't think we'd ever see a use case where method isn't equal to 'html', so good job!


Reply to this email directly or view it on GitHub.

Emanuele Cesena emanuele.cesena@gmail.com
http://www.theneeds.com

Il corpo non ha ideali

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants